<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Persons extends CI_Controller {

    
    function __construct() {
        parent::__construct();
        
        $this->load->model('Query_builder_model','qb'); 
        $param = array(
            'controller' => $this->controller,
            'header' => $this->header
        );
        $this->load->library('Crud', $param, 'cd');
        $this->load->library('Template', '', 'tpl');
        $this->load->model('Pagination_model', 'pg');
        
    }
    
    private $controller = 'persons';
    private $header = array('id'=>'ID',  'first_name'=>'First Name', 'last_name'=>'Last Name');

    public function index($action='list', $id=0) {
        
        $res = '';

        switch ($action) {
            case 'add':
                $res = $this->cd->c_add();
                break;
            case 'edit':
                $res = $this->cd->c_edit($id);
                break;
            case 'save':
                $id = $this->input->post('id');
                $res = $this->cd->c_save($id);
                break;
            default :
                $res = $this->cd->c_listing($id);
                break;
        }

        //echo $res;
        $this->tpl->initialize(array('current_page' => $res));
        echo $this->tpl->render();
    }
    
    
    function sort($field, $order='ASC'){
        $this->cd->set_sort(array('field'=>$field,'order'=>$order));
        $this->index();
    }

    
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */